package io.github.ali.commons.bean;

import io.github.ali.commons.beanutils.BeanCopierUtils;

/**
 * 可转换成其他POJO
 * 
 * @author fuli
 * @date 2019年2月13日
 * @version 1.0.0
 */
public interface Convertable {
	default <T>T convertTo(Class<T> targetClass){
		return BeanCopierUtils.copyOne2One(this, targetClass);
	}
	@SuppressWarnings("unchecked")
	default <T extends Convertable>T convertFrom(Object source){
		if (source == null) return null;
		BeanCopierUtils.copyProperties(source, this, null);
		return (T) this;
	}
	@SuppressWarnings("unchecked")
	default <T extends Convertable> T convertFrom(Object source, BeanCopierUtils.PropertyConverter propertyConverter) {
		if (source == null)
			return null;
		BeanCopierUtils.copyProperties(source, this, propertyConverter);
		return (T) this;
	}
}
